<!--Javascript-->
<script type="text/javascript" src="<?php echo base_url().'assets/js/jquery.min.js';?>"></script>
<script type="text/javascript" src="<?php echo base_url().'assets/js/bootstrap.min.js';?>"></script>
<script type="text/javascript" src="<?php echo base_url().'assets/js/bootstrap-datepicker.js';?>"></script>

<!-- Add mousewheel plugin (this is optional) -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>

<!-- Add fancyBox -->
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/lib/fancybox/source/jquery.fancybox.css?v=2.1.4" type="text/css" media="screen" />
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.4"></script>

<!-- Optionally add helpers - button, thumbnail and/or media -->
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/lib/fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" type="text/css" media="screen" />
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.5"></script>

<!-- datatables -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/datatables/js/jquery.dataTables.min.js"></script>

<!-- chosen -->
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/chosen/chosen.jquery.min.js"></script>

<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/lib/tinymce/js/tinymce/jquery.tinymce.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/big-modal.js"></script>
<script type="text/javascript">	
	var loader = "<img src='<?php echo base_url() ?>assets/img/ajax-loader.gif' >";
	var base_url = "<?php echo base_url() ?>";
	var thisId = 0;
    var currentTab = 1;
	
	$(document).ready(function(){
		
		$('.datepicker').datepicker({
				format: 'yyyy-mm-dd'
		});
		
		$('textarea.content').tinymce({
		  script_url : '<?php echo base_url(); ?>assets/lib/tinymce/js/tinymce/tinymce.min.js',
		  plugins : "media,image,code,autolink,anchor,link,table,advlist,template",		  
		  theme : "modern",
          
	   });
				
		$(".various").fancybox({
			maxWidth	: 800,
			maxHeight	: 600,
			fitToView	: false,
			width		: '70%',
			height		: '70%',
			autoSize	: false,
			closeClick	: false,
			openEffect	: 'none',
			closeEffect	: 'none',			
			
		});	
        
        $(".editModalTrigger").live('click',function(e){
             e.preventDefault();
            thisId = $(this).attr('rel');
            split = $(this).attr('rel').split('-');
            currentTab = split[1];
            $("#editUpload").attr('href','<?php echo base_url()."admin/file_upload_ads/tb_sys_advertising/"; ?>'+$(this).attr('rel')+'/strFilename');
            $("#editSave").attr('rel',split[0]);
            $.ajax({
			'url': '<?php echo base_url()."admin/get_ad/";?>'+split[1],
			'type': 'post',
			'dataType':'json',
			'data':{'intID':thisId},
			'success': function (data) {	
                $("#edit-enumPlayerLink").val(data.enumPlayerLink);
                $("#edit-fk-tb_mas_content").html(data.options);
                $("#edit-enumEnabled").val(data.enumEnabled);    
                $("#edit-strLink").val(data.strLink);
                $("#editImage").attr('src','http://ptv5-images.s3.amazonaws.com/'+data.strFilename);
                $("#edit-strFilename").val(data.strFilename);
                $("#edit-fk-tb_mas_content").val(data.content);
                $("#editModal").modal('show');
                
            }
            });
            
            
        });
        
        $(".addModalTrigger").live('click',function(e){
             e.preventDefault();
            split = $(this).attr('rel').split('-');
            currentTab = split[1];
            $.ajax({
			'url': '<?php echo base_url()."admin/new_ad/";?>'+split[1],
			'type': 'post',
			'dataType':'json',
			'data':{'fk-tb_sys_adspace':$(this).attr('rel'),'fk-tb_sys_adcampaign':'1','strLink':'http://www.pinoytuner.com','enumPlayerLink':'none'},
			'success': function (data) {	
                thisId = data.intID;
                $("#add-fk-tb_mas_content").html(data.options);
                $("#addUpload").attr('href','<?php echo base_url()."admin/file_upload_ads/tb_sys_advertising/"; ?>'+data.intID+'/strFilename');
                $("#addCancel").attr('rel',data.intID);
                $("#addSave").attr('rel',data.intID);    
                $("#addModal").modal('show');
            }
            });
            
        });
        
        $("#addCancel").live('click',function(e){
            e.preventDefault();
            $.ajax({
			'url': '<?php echo base_url()."admin/remove_ad";?>',
			'type': 'post',
			'dataType':'json',
			'data':{'intID':$(this).attr('rel')},
			'success': function (data) {
                
                $("#addModal").modal('hide');
                
            }
            });
           
        });
        $("#addSave").live('click',function(e){
            e.preventDefault();
            $.ajax({
			'url': '<?php echo base_url()."admin/update_ad";?>',
			'type': 'post',
			'dataType':'json',
			'data':{'intID':$(this).attr('rel'),'enumEnabled':$("#add-enumEnabled").val(),'strLink':$("#add-strLink").val(),'enumPlayerLink':$("#add-enumPlayerLink").val(),'strFilename':$("#add-strFilename").val(),'fk-tb_mas_content':$("#add-fk-tb_mas_content").val()},
			'success': function (data) {	
                window.location.href=base_url+'admin/advertising/'+currentTab;
                $("#addModal").modal('hide');
            }
            });
           
        });
        
        $("#editSave").live('click',function(e){
            e.preventDefault();
            $.ajax({
			'url': '<?php echo base_url()."admin/update_ad";?>',
			'type': 'post',
			'dataType':'json',
			'data':{'intID':$(this).attr('rel'),'enumEnabled':$("#edit-enumEnabled").val(),'strLink':$("#edit-strLink").val(),'enumPlayerLink':$("#edit-enumPlayerLink").val(),'strFilename':$("#edit-strFilename").val(),'fk-tb_mas_content':$("#edit-fk-tb_mas_content").val()},
			'success': function (data) {
                alert('Details Saved');
                window.location.href=base_url+'admin/advertising/'+currentTab;
                $("#editModal").modal('hide');
            }
            });
           
        });
        
        $(".removeAd").live('click',function(e){
        
            e.preventDefault();
            split = $(this).attr('rel').split('-');
            currentTab = split[1];
            $.ajax({
			'url': '<?php echo base_url()."admin/remove_ad";?>',
			'type': 'post',
			'dataType':'json',
			'data':{'intID':split[0]},
			'success': function (data) {	
                 window.location.href=base_url+'admin/advertising/'+currentTab;
               
            }
            });
            
        });
	
	   window.closeModal = function(filename){
           $.fancybox.close();
            $("#editImage").attr('src','http://ptv5-images.s3.amazonaws.com/'+filename);
            $("#addImage").attr('src','http://ptv5-images.s3.amazonaws.com/'+filename);
           $("#addImage").show(); 
           $("#edit-strFilename").val(filename);
           $("#add-strFilename").val(filename);
       };
 
          	   
	
    
    });
    
    
	
</script>

	